public class Solution6 {
    //712. 两个字符串的最小ASCII删除和
    public int minimumDeleteSum(String s1, String s2) {
        int m = s1.length();
        int n = s2.length();
        s1 = s1;
        s2 = s2;
        int[][] dp = new int[m+1][n+1];


        for (int i = 1; i < m+1; i++) {
            for (int j = 1; j < n+1; j++) {
                dp[i][j] = Math.max(dp[i][j-1],dp[i-1][j]);
                if (s1.charAt(i-1) == s2.charAt(j-1)) {
                    dp[i][j] = Math.max(dp[i][j],dp[i-1][j-1] + s1.charAt(i-1));
                }
            }
        }
        int sum =  0;
        for (char ch : s1.toCharArray()) sum += ch;
        for (char ch : s2.toCharArray()) sum += ch;
        return sum - dp[m][n]*2;
    }
}
